package com.study.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * 商品状态枚举类型
 */

@Getter
@AllArgsConstructor
public enum GoodsStatus {

    ONLINE(101, "上线"),
    OFFLINE(102, "下线"),
    STOCK_OUT(103, "货物不足"),;

    //状态码
    private final Integer status;

    //描述
    private final String description;

    public static GoodsStatus of(Integer status) {

        Objects.requireNonNull(status);

        return Stream.of(values())
                .filter(bean -> bean.equals(status))
                .findAny()
                .orElseThrow(
                        () -> new IllegalArgumentException(status + "不存在！")
                );
    }
}
